package iyuwu.PlayerManager;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.ArrayList;
import java.util.Collection;

public class CmdListener implements CommandExecutor {
    public void setAHead(ItemStack tmp,Player tmpP){
        ItemMeta im=tmp.hasItemMeta()?tmp.getItemMeta(): Bukkit.getItemFactory().getItemMeta(tmp.getType());
        im.setDisplayName(tmpP.getName());
        ArrayList<String> LoreList=new ArrayList<>();
        LoreList.add(ChatColor.RED+"玩家所在世界:");
        LoreList.add(ChatColor.GOLD+tmpP.getWorld().getName());
        LoreList.add(ChatColor.RED+"玩家坐标:");
        Location local=tmpP.getLocation();
        LoreList.add(ChatColor.GOLD+""+local.getX()+" "+local.getY()+" "+local.getZ());
        LoreList.add(ChatColor.RED+"玩家当前模式:");
        LoreList.add(ChatColor.GOLD+tmpP.getGameMode().name());
        LoreList.add(ChatColor.RED+"玩家当前血量:");
        LoreList.add(""+tmpP.getHealth());
        im.setLore(LoreList);
        tmp.setItemMeta(im);
    }
    @Override
    public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
        Inventory inv= Bukkit.createInventory(null,6*9,"Player list");
        Collection<? extends Player> p=Bukkit.getOnlinePlayers();
        int count=0;
        for(Player i:p){
            ItemStack n=new ItemStack(Material.SKULL_ITEM,1,(short)3);
            setAHead(n,i);
            inv.setItem(count,n);
            count++;
        }
        Player Sender=(Player) sender;
        Sender.openInventory(inv);
        return true;
    }
}
